<?php
namespace Admin\Controller;
use Think\Controller;
class LogController extends VController {
    public function index(){
        $log_modle = M('Log');
        $logList = $log_modle->where(array('state'=>0))->select();
        $this->assign('logList',$logList); 
        $this->display();
    }

    public function delete(){
        $log_modle = M('Log');
        $logList = $log_modle->where(array('state'=>4))->select();
        $this->assign('logList',$logList);
        $this->display();
    }

    public function detail(){
        $id=I('get.id');
        $log_modle = M('Log');
        $user_modle = M('User');
        $log = $log_modle->where(array('id'=>$id))->find();
        $user = $user_modle->where(array('id'=>$log['uid']))->find();
        $this->assign('log',$log);
        $this->assign('user',$user);
        $this->display();
    }
    //恢复日志
    public function back(){
        if(IS_AJAX){
            $id=I('post.id');
            $data['state']=0;
            $log_modle = M('Log');
            $res = $log = $log_modle->where(array('id'=>$id))->save($data);
            if($res){
                $rs['status'] = 'success';
                $rs['msg'] = '恢复成功';
                $rs['str'] = '删除';
                $rs['state'] = '0';
                $this->ajaxReturn($rs);
            }else{
                $rs['status'] = 'failed';
                $rs['msg'] = '恢复失败';
                $this->ajaxReturn($rs);
            }
        }else{
            $this->error('非法请求！');
        }
    }

     //删除日志
    public function del(){
        if(IS_AJAX){
            $id=I('post.id');
            $data['state']=4;
            $log_modle = M('Log');
            $res = $log = $log_modle->where(array('id'=>$id))->save($data);
            if($res){
                $rs['status'] = 'success';
                $rs['msg'] = '删除成功';
                $rs['str'] = '恢复';
                $rs['state'] = '4';
                $this->ajaxReturn($rs);
            }else{
                $rs['status'] = 'failed';
                $rs['msg'] = '删除失败';
                $this->ajaxReturn($rs);
            }
        }else{
            $this->error('非法请求！');
        }
    }
}